package BaseDatos;

import Servidor.Modelo.Games.Game;
import Servidor.Modelo.Users.User;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Angel Lopez
 */
public class PruebasBBDD extends javax.swing.JFrame {

    /**
     * Creates new form PruebasBBDD
     */
    public PruebasBBDD() {
        initComponents();
        listar_games();
        listar_users();
        listar_game_user();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelGames = new javax.swing.JPanel();
        jLabelTextGames = new javax.swing.JLabel();
        jLabelTextId_owner = new javax.swing.JLabel();
        jButtonNewGame = new javax.swing.JButton();
        jTextField_Id_owner = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaGames = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jButtonFinishGame = new javax.swing.JButton();
        jButtonReadyGames = new javax.swing.JButton();
        jTextFieldIDGame = new javax.swing.JTextField();
        jLabelIdGame = new javax.swing.JLabel();
        jTextFieldNameGame = new javax.swing.JTextField();
        jLabelNameGame = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabelTextGame_Player = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextAreaGamePlayer = new javax.swing.JTextArea();
        jPanelUser = new javax.swing.JPanel();
        jLabelTextUsers = new javax.swing.JLabel();
        jLabelId_user = new javax.swing.JLabel();
        jTextFieldID_User = new javax.swing.JTextField();
        jLabelNick = new javax.swing.JLabel();
        jTextFieldNick = new javax.swing.JTextField();
        jLabelPass = new javax.swing.JLabel();
        jTextFieldPass = new javax.swing.JTextField();
        jLabelMail = new javax.swing.JLabel();
        jTextFieldMail = new javax.swing.JTextField();
        jLabelType = new javax.swing.JLabel();
        jTextFieldTipo = new javax.swing.JTextField();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextAreaUsers = new javax.swing.JTextArea();
        jButtonNewUser = new javax.swing.JButton();
        jButtonUpdateUser = new javax.swing.JButton();
        jButtonSelect = new javax.swing.JButton();
        jButtonSelectNick = new javax.swing.JButton();
        jButtonSelectLogin = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanelGames.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabelTextGames.setText("GAMES");

        jLabelTextId_owner.setText("Id Owner");

        jButtonNewGame.setText("New Game");
        jButtonNewGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNewGameActionPerformed(evt);
            }
        });

        jTextField_Id_owner.setText("0");

        jTextAreaGames.setColumns(20);
        jTextAreaGames.setRows(5);
        jScrollPane1.setViewportView(jTextAreaGames);

        jLabel1.setText("ID GAME");

        jButtonFinishGame.setText("Finish");
        jButtonFinishGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFinishGameActionPerformed(evt);
            }
        });

        jButtonReadyGames.setText("Select Active Games");
        jButtonReadyGames.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonReadyGamesActionPerformed(evt);
            }
        });

        jTextFieldIDGame.setText("1");

        jLabelIdGame.setText("Id Game");

        jTextFieldNameGame.setText("Name Game");

        jLabelNameGame.setText("Name");

        javax.swing.GroupLayout jPanelGamesLayout = new javax.swing.GroupLayout(jPanelGames);
        jPanelGames.setLayout(jPanelGamesLayout);
        jPanelGamesLayout.setHorizontalGroup(
            jPanelGamesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelGamesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelGamesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelGamesLayout.createSequentialGroup()
                        .addGroup(jPanelGamesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanelGamesLayout.createSequentialGroup()
                                .addComponent(jButtonNewGame)
                                .addGap(18, 18, 18))
                            .addGroup(jPanelGamesLayout.createSequentialGroup()
                                .addComponent(jButtonFinishGame)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabelIdGame)
                                .addGap(1, 1, 1)))
                        .addGroup(jPanelGamesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelGamesLayout.createSequentialGroup()
                                .addComponent(jLabelTextId_owner)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextField_Id_owner, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(34, 34, 34)
                                .addComponent(jLabelNameGame)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldNameGame, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanelGamesLayout.createSequentialGroup()
                                .addGap(9, 9, 9)
                                .addComponent(jTextFieldIDGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(80, 80, 80)
                                .addComponent(jButtonReadyGames)))
                        .addGap(0, 232, Short.MAX_VALUE))
                    .addGroup(jPanelGamesLayout.createSequentialGroup()
                        .addGroup(jPanelGamesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelTextGames)
                            .addComponent(jLabel1))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );
        jPanelGamesLayout.setVerticalGroup(
            jPanelGamesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelGamesLayout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addComponent(jLabelTextGames)
                .addGap(21, 21, 21)
                .addGroup(jPanelGamesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonNewGame)
                    .addComponent(jLabelTextId_owner)
                    .addComponent(jTextField_Id_owner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNameGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNameGame))
                .addGap(26, 26, 26)
                .addGroup(jPanelGamesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonFinishGame)
                    .addComponent(jButtonReadyGames)
                    .addComponent(jTextFieldIDGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelIdGame))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 593, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabelTextGame_Player.setText("GAME-PLAYER");

        jTextAreaGamePlayer.setColumns(20);
        jTextAreaGamePlayer.setRows(5);
        jScrollPane3.setViewportView(jTextAreaGamePlayer);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabelTextGame_Player)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelTextGame_Player)
                .addGap(28, 28, 28)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jPanelUser.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabelTextUsers.setText("USERS");

        jLabelId_user.setText("Id User");

        jTextFieldID_User.setText("ID");

        jLabelNick.setText("Nick");

        jTextFieldNick.setText("Nick");

        jLabelPass.setText("Pass");

        jTextFieldPass.setText("Pass");

        jLabelMail.setText("Mail");

        jTextFieldMail.setText("Mail");

        jLabelType.setText("Type");

        jTextFieldTipo.setText("Type");

        jTextAreaUsers.setColumns(20);
        jTextAreaUsers.setRows(5);
        jScrollPane4.setViewportView(jTextAreaUsers);

        jButtonNewUser.setText("New User");
        jButtonNewUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNewUserActionPerformed(evt);
            }
        });

        jButtonUpdateUser.setText("Update");
        jButtonUpdateUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonUpdateUserActionPerformed(evt);
            }
        });

        jButtonSelect.setText("Select by ID");
        jButtonSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSelectActionPerformed(evt);
            }
        });

        jButtonSelectNick.setText("Select by Nick");
        jButtonSelectNick.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSelectNickActionPerformed(evt);
            }
        });

        jButtonSelectLogin.setText("Select Login");
        jButtonSelectLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSelectLoginActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelUserLayout = new javax.swing.GroupLayout(jPanelUser);
        jPanelUser.setLayout(jPanelUserLayout);
        jPanelUserLayout.setHorizontalGroup(
            jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelUserLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelUserLayout.createSequentialGroup()
                        .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelId_user)
                            .addComponent(jLabelNick)
                            .addComponent(jLabelPass)
                            .addComponent(jLabelMail)
                            .addComponent(jLabelType))
                        .addGap(32, 32, 32)
                        .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanelUserLayout.createSequentialGroup()
                                .addComponent(jTextFieldMail, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(jPanelUserLayout.createSequentialGroup()
                                .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldPass, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldNick, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldID_User, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
                                .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButtonSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jButtonUpdateUser, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jButtonNewUser))
                                    .addComponent(jButtonSelectNick)
                                    .addComponent(jButtonSelectLogin))
                                .addGap(61, 61, 61))))
                    .addComponent(jScrollPane4)
                    .addGroup(jPanelUserLayout.createSequentialGroup()
                        .addComponent(jLabelTextUsers)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanelUserLayout.setVerticalGroup(
            jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelUserLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelUserLayout.createSequentialGroup()
                        .addComponent(jButtonNewUser)
                        .addGap(40, 40, 40))
                    .addGroup(jPanelUserLayout.createSequentialGroup()
                        .addComponent(jLabelTextUsers)
                        .addGap(18, 18, 18)
                        .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelId_user)
                            .addComponent(jTextFieldID_User, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelNick)
                            .addComponent(jTextFieldNick, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonUpdateUser))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelPass)
                        .addComponent(jTextFieldPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButtonSelect, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelUserLayout.createSequentialGroup()
                        .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelMail)
                            .addComponent(jTextFieldMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelType)
                            .addComponent(jTextFieldTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18))
                    .addGroup(jPanelUserLayout.createSequentialGroup()
                        .addComponent(jButtonSelectNick)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonSelectLogin)
                        .addGap(15, 15, 15)))
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelUser, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanelGames, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanelGames, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonNewGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewGameActionPerformed
        
        FachadaBBDD.get_instance().insert_game(Integer.parseInt(jTextField_Id_owner.getText()), jTextFieldNameGame.getText());
        
        listar_games();
        
    }//GEN-LAST:event_jButtonNewGameActionPerformed

    private void jButtonFinishGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFinishGameActionPerformed
        FachadaBBDD.get_instance().update_game_finish_date(Integer.parseInt(jTextFieldIDGame.getText()));
    }//GEN-LAST:event_jButtonFinishGameActionPerformed

    private void jButtonNewUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewUserActionPerformed
        User user_aux = new User(jTextFieldNick.getText(), jTextFieldPass.getText(), jTextFieldMail.getText(), Integer.parseInt(jTextFieldTipo.getText()));
        
        listar_users();
    }//GEN-LAST:event_jButtonNewUserActionPerformed

    private void jButtonUpdateUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonUpdateUserActionPerformed
        FachadaBBDD.get_instance().update_user(Integer.parseInt(jTextFieldID_User.getText()), jTextFieldNick.getText(), jTextFieldPass.getText(), jTextFieldMail.getText(), Integer.parseInt(jTextFieldTipo.getText()));
        listar_users();
    }//GEN-LAST:event_jButtonUpdateUserActionPerformed

    private void jButtonSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectActionPerformed
        User user = FachadaBBDD.get_instance().select_user(Integer.parseInt(jTextFieldID_User.getText()));
        jTextFieldID_User.setText(""+user.getId_user());
        jTextFieldNick.setText(user.getNick());
        jTextFieldPass.setText(user.getPass());
        jTextFieldMail.setText(user.getEmail());
        jTextFieldTipo.setText(""+user.getType_user());
    }//GEN-LAST:event_jButtonSelectActionPerformed

    private void jButtonSelectNickActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectNickActionPerformed
        User user = FachadaBBDD.get_instance().select_user_by_nick(jTextFieldNick.getText());
        jTextFieldID_User.setText(""+user.getId_user());
        jTextFieldNick.setText(user.getNick());
        jTextFieldPass.setText(user.getPass());
        jTextFieldMail.setText(user.getEmail());
        jTextFieldTipo.setText(""+user.getType_user());
    }//GEN-LAST:event_jButtonSelectNickActionPerformed

    private void jButtonSelectLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectLoginActionPerformed
        jTextFieldTipo.setText(""+FachadaBBDD.get_instance().select_user_login(jTextFieldNick.getText(), jTextFieldPass.getText()));
    }//GEN-LAST:event_jButtonSelectLoginActionPerformed

    private void jButtonReadyGamesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonReadyGamesActionPerformed
        listar_active_games();
    }//GEN-LAST:event_jButtonReadyGamesActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PruebasBBDD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PruebasBBDD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PruebasBBDD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PruebasBBDD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new PruebasBBDD().setVisible(true);
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonFinishGame;
    private javax.swing.JButton jButtonNewGame;
    private javax.swing.JButton jButtonNewUser;
    private javax.swing.JButton jButtonReadyGames;
    private javax.swing.JButton jButtonSelect;
    private javax.swing.JButton jButtonSelectLogin;
    private javax.swing.JButton jButtonSelectNick;
    private javax.swing.JButton jButtonUpdateUser;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelIdGame;
    private javax.swing.JLabel jLabelId_user;
    private javax.swing.JLabel jLabelMail;
    private javax.swing.JLabel jLabelNameGame;
    private javax.swing.JLabel jLabelNick;
    private javax.swing.JLabel jLabelPass;
    private javax.swing.JLabel jLabelTextGame_Player;
    private javax.swing.JLabel jLabelTextGames;
    private javax.swing.JLabel jLabelTextId_owner;
    private javax.swing.JLabel jLabelTextUsers;
    private javax.swing.JLabel jLabelType;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelGames;
    private javax.swing.JPanel jPanelUser;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextArea jTextAreaGamePlayer;
    private javax.swing.JTextArea jTextAreaGames;
    private javax.swing.JTextArea jTextAreaUsers;
    private javax.swing.JTextField jTextFieldIDGame;
    private javax.swing.JTextField jTextFieldID_User;
    private javax.swing.JTextField jTextFieldMail;
    private javax.swing.JTextField jTextFieldNameGame;
    private javax.swing.JTextField jTextFieldNick;
    private javax.swing.JTextField jTextFieldPass;
    private javax.swing.JTextField jTextFieldTipo;
    private javax.swing.JTextField jTextField_Id_owner;
    // End of variables declaration//GEN-END:variables
    
    private void listar_games(){
        ArrayList<Game> list_games = FachadaBBDD.get_instance().select_list_games();
        
        Iterator iter = list_games.iterator();
        String linea = "";
        while (iter.hasNext()){
            Game game_aux = (Game)iter.next();
            
            linea = "(" + game_aux.getId_game() + ") - NAME(" + game_aux.getName_game()  + ") - OWNER(" + game_aux.getId_owner()  + ") - WINNER(" + game_aux.getId_winner()  + ") - START(" + game_aux.getDate_start()+ ") - FINISH(" + game_aux.getDate_finish() + ")\n" + linea ;
            
            jTextAreaGames.setText(linea);
        }
    }
    
        private void listar_active_games(){
        ArrayList<Game> list_games = FachadaBBDD.get_instance().select_list_games_active();
        
        Iterator iter = list_games.iterator();
        String linea = "";
        while (iter.hasNext()){
            Game game_aux = (Game)iter.next();
            
            linea = "(" + game_aux.getId_game() + ") - NAME(" + game_aux.getName_game()  + ") - OWNER(" + game_aux.getId_owner()  + ") - WINNER(" + game_aux.getId_winner()  + ") - START(" + game_aux.getDate_start()+ ") - FINISH(" + game_aux.getDate_finish() + ")\n" + linea ;
            
            jTextAreaGames.setText(linea);
        }
    }
    
    private void listar_users(){
        ArrayList<User> list_users = FachadaBBDD.get_instance().select_list_users();
        
        Iterator iter = list_users.iterator();
        String linea = "";
        while (iter.hasNext()){
            User user_aux = (User)iter.next();
            
            linea = "USER(" + user_aux.getId_user() + ") - NICK(" + user_aux.getNick()  + ") - PASS(" + user_aux.getPass()  + ") - TYPE(" + user_aux.getType_user()+ ") \n" + linea ;
            
            jTextAreaUsers.setText(linea);
        }
    }
    
        private void listar_game_user(){
        ArrayList<String> list_users = FachadaBBDD.get_instance().select_player();
        
        Iterator iter = list_users.iterator();
        String linea = "";
        while (iter.hasNext()){
            linea = (String) iter.next() + "\n" + linea;
            
            jTextAreaGamePlayer.setText(linea);
        }
    }



}
